﻿//===============================================================================
// Microsoft Innovation Centre - Western Europe
// Copyright (c) 2008 Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.ComponentModel;
using Microsoft.WVB.Silverlight.Infrastructure;

namespace Microsoft.WVB.Framework
{
    public class User<T,K> : IUser
        where T: class, IMembershipUser, new()
        where K: class, IProfileInfo, new()
    {
        protected IMembershipUser _userCredentials = default(T);
        protected IProfileInfo _userProfileInfo = default(K);

        public IMembershipUser UserCredentials { set { _userCredentials = value; } get { return _userCredentials; } }
        public IProfileInfo ProfileInfo { set { _userProfileInfo = value; } get { return _userProfileInfo; } }

        public event PropertyChangedEventHandler PropertyChanged;

        public User()
        {
            _userCredentials = new T();
            _userProfileInfo = new K();
        }

        protected virtual void OnNotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public virtual String PPID
        {
            get { return _userCredentials.UserName; }
            set
            {
                if (value != null)
                {
                    _userCredentials.UserName = value;
                    OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.PPID));
                }
            }
        }

        public virtual Gender Gender
        {
            get
            {
                return _userProfileInfo.Gender;               
            }
            set
            {
                if (value.GetType() == Gender.GetType())
                {
                    _userProfileInfo.Gender = value;
                    OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.Gender));
                }
            }
        }

        public virtual String Email 
        { 
            get
            {
                return _userCredentials.Email;
            }
            set
            {
                if (value != null)
                {
                    _userCredentials.Email = value;
                    OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.Email));
                }
            }
        }

        public virtual String FirstName
        {
            get
            {
                if (this._userProfileInfo.FirstName != null)
                    return _userProfileInfo.FirstName;
                else
                    return default(string);
            }
            set
            {
                if (value != null)
                {
                    _userProfileInfo.FirstName = value;
                    OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.FirstName));
                }
            }
        }

        public virtual String LastName
        {
            get
            {
                if (_userProfileInfo.LastName != null)
                    return _userProfileInfo.LastName;
                else
                    return default(string);
            }
            set
            {
                if (value != null)
                {
                    _userProfileInfo.LastName = value;
                    OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.LastName));
                }
            }
        }

        public virtual DateTime? BirthDate
        {
            get
            {
                return _userProfileInfo.BirthDate;
            }
            set
            {
                if (value != null)
                {
                    _userProfileInfo.BirthDate = value;
                    OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.BirthDate));
                }
            }
        }

        public virtual int? ZipCode
        {
            get
            {
                return _userProfileInfo.ZipCode;
            }
            set
            {
                _userProfileInfo.ZipCode = value;
                OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.ZipCode));
            }
        }

        public virtual String Country
        {
            get
            {
                if (_userProfileInfo.Country != null)
                    return _userProfileInfo.Country;
                else
                    return default(String);
            }
            set
            {
                if (value != null)
                {
                    _userProfileInfo.Country = value;
                    OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.Country));
                }
            }
        }

        public virtual String JobTitle
        {
            get
            {
                if (_userProfileInfo.JobTitle != null)
                    return _userProfileInfo.JobTitle;
                else
                    return default(String);
            }
            set
            {
                if (value != null)
                {
                    _userProfileInfo.JobTitle = value;
                    OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.JobTitle));
                }
            }
        }

        public virtual String Industry
        {
            get
            {
                if (_userProfileInfo.Industry != null)
                    return _userProfileInfo.Industry;
                else
                    return default(String);
            }
            set
            {
                if (value != null)
                {
                    _userProfileInfo.Industry = value;
                    OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.Industry));
                }
            }
        }

        public virtual double? Income
        {
            get
            {
                return _userProfileInfo.Income;
            }
            set
            {
                _userProfileInfo.Income = value;
                OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.Income));
            }
        }

        public virtual int? CompanySize
        {
            get
            {
                return _userProfileInfo.CompanySize;
            }
            set
            {
                _userProfileInfo.CompanySize = value;
                OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.CompanySize));
            }
        }

        public virtual String Interests
        {
            get
            {
                if (_userProfileInfo.Interests != null)
                    return _userProfileInfo.Interests;
                else
                    return null;
            }
            set
            {
                if (value != null)
                {
                    _userProfileInfo.Interests = value;
                    OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.Interests));
                }
            }
        }

        public ProfileLevel Level
        {
            get
            {
                return _userProfileInfo.Level;
            }
        }

        public virtual String Password
        {
            get { return _Password; }
            set { _Password = value; OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.Password)); }
        }
        private String _Password = null;

        public virtual String RetypedPassword
        {
            get { return _RetypedPassword; }
            set { _RetypedPassword = value; OnNotifyPropertyChanged(this.GetPropertySymbol(o => o.RetypedPassword)); }
        }
        private String _RetypedPassword = null;
    }
}
